package com.it.orderservice.service.impl;

import com.it.*;
import com.it.commonutils.ordervo.CourseWebVoOrder;
import com.it.commonutils.ordervo.UcenterMemberOrder;
import com.it.orderservice.client.EduClient;
import com.it.orderservice.client.UcenterClient;
import com.it.orderservice.entity.Order;
import com.it.orderservice.mapper.OrderMapper;
import com.it.orderservice.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.it.orderservice.utils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author test.java
 * @since 2021-04-22
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private EduClient eduClient;

    @Autowired
    private UcenterClient ucenterClient;

    //生成订单的方法
    public String createOrders(String courseId, String memberId) {
        //需要课程信息和用户信息 通过远程调用得到
        //通过远程调用得到根据用户id获取用户信息
        UcenterMemberOrder userInfoOrder = ucenterClient.getUserInfoOrder(memberId);
        //通过远程调用得到根据课程id获取课程信息
        CourseWebVoOrder courseInfoOrder = eduClient.getCourseInfoOrder(courseId);


        //生成订单
        Order order=new Order();
        order.setOrderNo(OrderNoUtil.getOrderNo());//订单号
        order.setCourseId(courseId);//课程id
        order.setCourseTitle(courseInfoOrder.getTitle());//课程标题
        order.setCourseCover(courseInfoOrder.getCover());//课程封面
        order.setTeacherName(courseInfoOrder.getTeacherName());//讲师姓名

        order.setTotalFee(courseInfoOrder.getPrice());//

        order.setMemberId(memberId);//
        order.setMobile(userInfoOrder.getMobile());
        order.setNickname(userInfoOrder.getNickname());
        order.setStatus(0); //支付状态
        order.setPayType(1);//支付类型 微信
        baseMapper.insert(order);
        //返回订单号
        return order.getOrderNo();


    }



}
